package jdbc;

import java.sql.*;

public class JDBCDemo {



    public static void main(String[] args) throws ClassNotFoundException, SQLException {

//        Class.forName("com.mysql.cj.jdbc.Driver");

        Connection conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root","root"
        );

        Statement s = conn.createStatement();

        String sql = "select * from teacher";
        ResultSet rs = s.executeQuery(sql);
        while (rs.next()){
            int id = rs.getInt(1);
            String name = rs.getString(2);
            int age = rs.getInt(3);
            String title = rs.getString(4);
            int manager = rs.getInt(5);
            Double salary = rs.getDouble(6);
            Double comm = rs.getDouble(7);
            String gender = rs.getString(8);
            Integer subject_id = rs.getInt(9);
            System.out.println(id+","+name+","+age+","+title+","+manager+","+salary+","+comm+","+gender+","+subject_id);
        }

        System.out.println("数据库连接成功");
    }
}
